// pages/draw/index.js
const common = require("../../public.js");
Page({
    data: {
        payClick:false,
        totalCount:3,
        joinOne:false,// 只访问一次接口
        isOverShare: true,  //全局分享标识请勿删除
        userInfo: '',
        token: '',
        drawId: '', // 抽奖id
        inviteUserId: '', // 邀请用户id
        drawInfo: '', // 抽奖详情
        currentTimestamp:'',
        AllApplyUserList: [], // 参与用户
        bannerImgList: [], // 轮播图片列表
        userCount: 0, //参与人数
        joinUseList: [],
        showPop: false,
        showDownload: false,
        active: 0,
        indicatorDots: false,
        vertical: false,
        autoplay: false,
        interval: 2000,
        duration: 500,
        backToApp: false,
        open_vip: false,
        vip_list: [],
        swiper_current: 0,
        tabs_active: 0,
        scroll_into_view: '',
        isReceiveApplyMoney: '',
        card_id: 0,
        isSelect: true,
        isSubStore: false,
        shownSucess: false, //报名成功弹框
        imgBgc: 'https://feiyangimage.oss-cn-shanghai.aliyuncs.com/severs_ke_c.png', //绘制背景
        from: '',
        serviceShow: false
    },
    close_toast_func(){
        this.setData({
            shownSucess:false
        })
    },
    click_share() {
           console.log("hhhh")
           this.onShareAppMessage();
        this.getStoreDrawUserdInfos()
        this.setData({
            shownSucess:false
        })
    },
    getStoreDrawUserdInfos() { // 获得所有参与者头像
        let that = this
        let tempJson = {
            drawId: that.data.drawId,

        }
        common.post("/storeDraw/saveStoreDrawShareNum", tempJson, function (res) {
            console.log('storeDraw/saveStoreDrawShareNum---',res);
            if (res.status === 200) {

            }
        })
    },
    goBack() {
        console.log("fanhui")
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })
        } else {
            wx.redirectTo({
                url: '/pages/index/index',
            })
        }
    },
    // 添加客服
    go_addService() {
        wx.navigateTo({
            url: `/packageC/pages/addService/addService?imgCode=${this.data.drawInfo.customerQrcode}`,
        })
        // const that = this  
        // let imgCode = this.data.drawInfo.customerQrcode ? this.data.drawInfo.customerQrcode : ''
        // var str = imgCode.split(':')
        // console.log(str)
        // var headApply = 'https:'
        // var imgcodeUrl = headApply + str[1]
        // console.log(imgcodeUrl)
        // that.setData({
        //     serviceShow:true,
        //     imgCode: imgcodeUrl
        // }, () => {
        //     this.fn()
        // })

    },
    touchstart(e) {
        console.log(e, "kkkkkkhhjhhhh")
        if (e.timeStamp >= 2000) {  /*长按两秒*/
            this.savePhoto() //响应事件
        }

        this.setData({
            touchstart: e.timeStamp
        })
    },
    // 绘制方法
    fn() {
        let that = this
        const ctx = wx.createCanvasContext("myCanvas", that)
        wx.downloadFile({
            url: that.data.imgBgc,
            success: function (res) {
                console.log(res, "海报图片")
                let imgBgc = res.tempFilePath

                // 获取图片信息，要按照原图来绘制，否则图片会变形 
                wx.getImageInfo({
                    src: imgBgc,
                    success: function (res) {
                        // 根据 图片的大小 绘制底图 的大小
                        console.log(" 绘制底图 的图片信息》》》", res)
                        let imgW = res.width
                        let imgH = res.height
                        let imgPath = res.path
                        that.setData({
                            canvasHeight: wx.getSystemInfoSync().windowHeight,
                            canvasWidth: wx.getSystemInfoSync().windowWidth,
                            ctx,
                        }, () => {
                            ctx.drawImage(imgPath, 0, 0, 340, 460)
                        })

                        // 二维码
                        wx.downloadFile({
                            url: that.data.imgCode,
                            success: function (res) {
                                let imgCode = res.tempFilePath
                                // 创建画布对象
                                wx.getImageInfo({
                                    src: imgCode, // 二维码图片的路径
                                    success: function (res) {
                                        let imgPaths = res.path
                                        ctx.drawImage(imgPaths, wx.getSystemInfoSync().safeArea.width / 3.8, wx.getSystemInfoSync().safeArea.height / 4.35, 140, 140)
                                        ctx.draw()

                                    }
                                })
                            }

                        })
                        // 

                    }
                })

            }
        })



    },
    savePhoto() {
        var that = this
        wx.showLoading({
            title: '正在保存',
            mask: true
        })
        that.data.ctx.fileType = "#ffff"
        that.data.ctx.draw(true, function () {
            setTimeout(() => {
                wx.canvasToTempFilePath({
                    fileType: 'png',
                    canvasId: 'myCanvas',
                    success: function (res) {
                        let tempFilePath = res.tempFilePath
                        // 保存到相册
                        wx.saveImageToPhotosAlbum({
                            filePath: tempFilePath,
                            success(res) {
                                wx.hideLoading()
                                wx.showModal({
                                    title: '温馨提示',
                                    content: '图片保存成功，可在相册中查看',
                                    showCancel: false,
                                    success(res) {
                                        wx.clear
                                        if (res.confirm) {
                                            that.setData({
                                                isShow: true
                                            })
                                        }
                                    },
                                    fail(res) {
                                        wx.hideLoading()
                                        wx.showModal({
                                            title: '温馨提示',
                                            content: '图片保存失败，请重试',
                                            showCancel: false
                                        })
                                    }
                                })

                            },
                            fail(res) {
                                wx.hideLoading()
                                if (res.errMsg == "saveImageToPhotosAlbum:fail auth deny") {
                                    wx.hideLoading()
                                    wx.showModal({
                                        title: '检测到您没有打开保存到相册的权限，是否前往设置打开？',
                                        success: (res) => {
                                            if (res.confirm) {
                                                that.onOpenSetting() // 打开设置页面          
                                            } else if (res.cancel) {

                                            }
                                        }
                                    })

                                }
                            }
                        })
                    },
                    fail(res) {
                        wx.hideLoading()

                    }

                })

            }, 1500)
        })

    },
    //打开设置，引导用户授权
    onOpenSetting() {
        var that = this
        wx.openSetting({
            success: (res) => {
                if (!res.authSetting['scope.writePhotosAlbum']) {
                    wx.showToast({
                        title: '您未授权',
                        icon: 'none',
                        duration: 1500
                    })
                    that.setData({ // 拒绝授权
                        isAuthSavePhoto: true
                    })

                } else { // 接受授权
                    that.setData({
                        isAuthSavePhoto: false
                    })
                    that.savePhoto() // 接受授权后保存图片

                }

            }
        })

    },
    arrayBufferToBase64(buffer) {
        var binary = '';
        var bytes = new Uint8Array(buffer);
        var len = bytes.byteLength;
        for (var i = 0; i < len; i++) {
            binary += String.fromCharCode(bytes[i]);
        }
        return "data:image/png;base64," + this.btoa(binary);
    },

    btoa(string) {
        var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
        string = String(string);
        var bitmap, a, b, c,
            result = "",
            i = 0,
            rest = string.length % 3; // To determine the final padding

        for (; i < string.length;) {
            if ((a = string.charCodeAt(i++)) > 255 ||
                (b = string.charCodeAt(i++)) > 255 ||
                (c = string.charCodeAt(i++)) > 255)
                throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");

            bitmap = (a << 16) | (b << 8) | c;
            result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63) +
                b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);
        }

        // If there's need of padding, replace the last 'A's with equal signs
        return rest ? result.slice(0, rest - 3) + "===".substring(rest) : result;
    },
    // 打电话
    call() {
        // 飞羊精选 https://work.weixin.qq.com/kfid/kfca7da70439f63aef6
        console.log('获客链接--', this.data.drawInfo.enterchatUrl)
        if(this.data.drawInfo.enterchatUrl){
            wx.openCustomerServiceChat({
                extInfo: {url: this.data.drawInfo.enterchatUrl},
                corpId: 'wwdf30d8a07ffbd1e7',
                success(res) {
                    console.log('成功打开客服聊天界面res---', res);
                },
                fail(err) {
                    common.showToast(err.errMsg)
                  console.log('打开客服聊天界面失败err--', err);
                }
          
              })
        }else{
         
            common.showToast('暂无客服链接')
        }
 
return;
        // 
        let mobile = this.data.drawInfo.storePhone
        wx.makePhoneCall({
            phoneNumber: mobile,
        })
    },
    onLoad: function (options) {
        // wx.hideHomeButton()
        console.log("ffff---",options)
        let that = this
        //获取胶囊位置
        let capsule = wx.getMenuButtonBoundingClientRect()
        this.setData({
            height: capsule.height,
            top: capsule.top,
        })
        console.log(wx.getSystemInfoSync(), "ooooooo")
        var windowHeight = wx.getSystemInfoSync().windowHeight
        var windowWidth = wx.getSystemInfoSync().windowWidth
        this.setData({
            scroll_height: windowHeight * 750 / windowWidth - 200
        })
        this.setData({
            drawId: options.drawId ? options.drawId : 234,
            inviteUserId: options.inviteUserId || '',
            isReceiveApplyMoney: options.isReceiveApplyMoney == 'true' ? true : false,
            from: options.from ? options.from : ''
        }, () => {
            that.getDrawInfo()

        })
        if (options.q) {
            let scan_url = decodeURIComponent(options.q);
            let video_id = scan_url.match(/\d+/) //提取链接中的数字，也就是链接中的参数id，/\d+/ 为正则表达式s
            common.getLocalUserInfo(function (success, userInfo) {
                if (success) {
                    getApp().getLocation(function (data) {
                        that.setData({
                            drawId: video_id[0],
                            userInfo: userInfo.user,
                            token: userInfo.token,
                            openid: userInfo.openid
                        }, function () {
                            that.getDrawInfo()
                            that.getStoreDrawUserdInfo()
                        })
                    })
                } else {
                    common.showLoginPage()
                }
            }, true)
            return
        } else {
            wx.getStorage({
                key: 'user',
                success: function (res) {
                    that.setData({
                        userInfo: res.data.user,
                        token: res.data.token,
                        // drawId: options.drawId,
                        // inviteUserId: options.inviteUserId || '',
                        // isReceiveApplyMoney: options.isReceiveApplyMoney == 'true' ? true : false,

                        openid: res.data.openid
                    }, () => {
                        that.getStoreDrawUserdInfo()
                        // that.getDrawInfo()
                    })
                },
                fail: function () {
                    common.showLoginPage()
                }
            })
        }
    },

    // tabs改变
    tabsChange(e) {
        let index = e.detail.index;
        if (index == 0) {
            this.setData({
                scroll_into_view: 'goodsTitle',
            })
        } else if (index == 1) {
            this.setData({
                scroll_into_view: 'rule',
            })
        } else if (index == 2) {
            this.setData({
                scroll_into_view: 'invitation',
            })
        } else if (index == 3) {
            this.setData({
                scroll_into_view: 'detailDesc',
            })
        }

        // console.log(this.data.scroll_into_view)
    },
    // 轮播图滚动
    swiperChange(e) {
        this.setData({
            swiper_current: e.detail.current
        })
    },
    // 轮播图滚动
    vipSwiperChange(e) {
        this.setData({
            card_id: this.data.vip_list[e.detail.current].id
        })
    },
    toOpenVip() {
        wx.navigateTo({
            url: '/pages/myNian/payCard/payCard?cardId=' + this.data.card_id
        })
    },
    // https://api.feiyanghy.com/storeDraw/getStoreDrawUserdInfo
    getStoreDrawUserdInfo() { // 获得所有参与者头像
        let that = this
        let tempJson = {
            drawId: that.data.drawId,
            userId: that.data.userInfo.id
        }
        common.post("/storeDraw/getStoreDrawUserdInfo", tempJson, function (res) {
            if (res.status === 200) {
                that.setData({
                    // joinUseList: res.data.userList,
                    // userCount: res.data.userCount
                })
            }
        })
    },
    getDrawInfo() { // 获得抽奖详情
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        let that = this
        let tempJson = {
            drawId: that.data.drawId,
            userId: that.data.userInfo.id ? that.data.userInfo.id : '',
            // userId : ''
        }
        common.post("/storeDraw/getStoreDrawInfo", tempJson, function (res) {
            if (res.status === 200) {

                //                 res.data.myInviteList=[
                //                     {headImgurl:'1',
                //                     alias:'ss'
                //                 },
                //                 {headImgurl:'1',
                //                 alias:'ss'
                //             },
                //             {headImgurl:'1',
                //             alias:'ss'
                //         },
                //         {headImgurl:'1',
                //         alias:'ss'
                //     },
                //     {headImgurl:'1',
                //     alias:'ss'
                // },
                // {headImgurl:'1',
                // alias:'ss'
                // },
                // {headImgurl:'1',
                // alias:'ss'
                // },
                //                 ]
                let list = res.data.myInviteList ? res.data.myInviteList : '';
                const richText = res.data.detailDesc ? res.data.detailDesc.replace(/\<img/gi, "<img mode='aspectFill' ") : ''
                let str = richText.replace(/<img[^>]*>/gi, function (match, capture) {
                    return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="max-width:100%;height:auto; width:100%";height:100%') // 替换style

                })

                let new_arr = [];
                if (list) {
                    list.forEach((item, index) => {
                        if (index % 5 == 0) {
                            new_arr.push([]);
                        }
                        new_arr[new_arr.length - 1].push(item);
                    });
                }

                let qy = 5 - (list.length % 5);
                if (qy == 5) {
                    new_arr.push([]);
                    for (let index = 0; index < 5; index++) {
                        new_arr[new_arr.length - 1].push([]);
                    }
                } else {
                    for (let index = 0; index < qy; index++) {
                        new_arr[new_arr.length - 1].push([]);
                    }
                }
                console.log(new_arr)
                // res.data.status=3
                res.data.new_myInviteList = new_arr;
                res.data.detailDesc = !res.data.detailDesc ? res.data.detailDesc : res.data.detailDesc.replace(/<img /i, "<img style='width: 100%;' ");
                that.setData({
                    goodsInformation: str,
                    drawInfo: res.data,
                    currentTimestamp:Date.parse(new Date()),
                    bannerImgList: res.data.otherPictureList,
                }, _ => {
                    wx.hideLoading()
                    that.data.payClick = false;
                    console.log('当前时间戳---',that.data.currentTimestamp);
                    that.getAllApplyUserList()
                    that.isDingYue(res.data.storeId)
                })
            } else {
                wx.hideLoading()
                that.data.payClick = false;
                common.showRequestErrMsg(res)
            }
        }, function () {
            wx.hideLoading()
        })
    },
    // 检测是否订阅
    isDingYue(storeId) {
        let that = this
        let tempJson = {
            userId: this.data.userInfo.id,
            token: this.data.token,
            storeId: this.data.drawInfo.storeId
        }
        common.post("/store/favo/isSubStore", tempJson, function (res) {
            // if (res.status === 200) {
            console.log(res.data)
            if (res.data != null && res.data) {
                console.log("666666")
                that.setData({
                    isSubStore: true  //已订阅
                })
            } else {
                console.log("77777")
                that.setData({
                    isSubStore: false  //已订阅
                })
            }

            // }
        })
    },
    // 订阅
    subStore() {
        let that = this
        let tempJson = {
            userId: this.data.userInfo.id,
            token: this.data.token,
            storeId: this.data.drawInfo.storeId
        }
        let url = this.data.isSubStore ? '/store/favo/deleteSubStore' : '/store/favo/addSubStore'
        common.post(url, tempJson, function (res) {
            if (res.status === 200) {
                that.isDingYue()
            }
        })
    },
    getAllApplyUserList() { // 获得所有参与者头像
        let that = this
        let tempJson = {
            drawId: that.data.drawInfo.id
        }
        common.post("/storeDraw/getAllApplyUserList", tempJson, function (res) {
            if (res.status === 200) {
                that.setData({
                    joinUseList: res.data.userList,
                    userCount: res.data.userCount
                })
            }
        })
    },
    joinNow() { // 立即参与
        if (this.data.userInfo.id) {
            this.setData({
                showPop: true
            })
        } else {
            common.showToast('请点击右下方前往小程序')
        }

    },
    onClose() { //关闭模态框
        this.setData({
            showPop: false,
            showDownload: false,
            backToApp: false,
            open_vip: false,
        })
    },
    // startDraw: common.throttleFunc(function (e) { //立刻报名
    startDraw(e) { //立刻报名
        wx.showLoading({
            title: '正在调起支付',
          })
        // startDraw() { //立刻报名
        let that = this;
        if(that.data.payClick == true){

            console.log('禁止连续点击');
            return;
        }
        that.data.payClick = true;
        let status = e.currentTarget.dataset.status
        console.log('gg===',status,'====isSelect==',that.data.isSelect);
        if (status == 2) {

            this.fns()


        }
        return;

        // return;
        // if (status == 2) {
            // if (that.data.isSelect == true) {
            //     that.setData({
            //         isSelect: false
            //     });

                // that.run20Func();
                // that.run20Func();

                wx.requestSubscribeMessage({
                    // 调起消息订阅界面
                    tmplIds: ['rricZW0B8--bBdmyXPdt_Grmz4D9yN9N_TzgK2T0p4Y'],// fYXeGpc3zMvjC07fyBkBsBBLWWaUYtZ8XOHgEBJ_n4o
                    success(res) {
                        console.log('aa订阅消息 成功 ');
                        console.log(res)
                    },
                    fail(er) {
                        console.log("aa订阅消息 失败 ");
                        console.log(er)
                    },
                           
                           
    
                    complete: (errMsg) => {
                        console.log("aa数据",errMsg)
                        that.setData({
                            totalCount:that.data.totalCount - 1
                        },()=>{
                            // setTimeout(function() {
                            //     // 这里是延迟执行的代码
                            //     that.run20Func();
                            //     // that.startDraw();
                            //   }, 3000);
                           
                        })
                       
                        
                    }
                })

         
                            
                         
                wx.requestSubscribeMessage({
                    // 调起消息订阅界面
                    tmplIds: ['rricZW0B8--bBdmyXPdt_Grmz4D9yN9N_TzgK2T0p4Y'],// fYXeGpc3zMvjC07fyBkBsBBLWWaUYtZ8XOHgEBJ_n4o
                    success(res) {
                        console.log('bb订阅消息 成功 ');
                        console.log(res)
                    },
                    fail(er) {
                        console.log("bb订阅消息 失败 ");
                        console.log(er)
                    },
                           
                           
    
                    complete: (errMsg) => {
                        console.log("bb数据",errMsg)
                        that.setData({
                            totalCount:that.data.totalCount - 1
                        },()=>{
                            // setTimeout(function() {
                            //     // 这里是延迟执行的代码
                            //     that.run20Func();
                            //     // that.startDraw();
                            //   }, 3000);
                           
                        })
                       
                        
                    }
                })
   
              
            // }


        // }

    // }, 3000),
    },


    run20Func(){
        var that = this;

        // if(that.data.totalCount==0){
        //     console.log('totalCount为---',that.data.totalCount);
        //         that.fns();
        //     return;
        // }
            wx.requestSubscribeMessage({
                // 调起消息订阅界面
                tmplIds: ['rricZW0B8--bBdmyXPdt_Grmz4D9yN9N_TzgK2T0p4Y'],// fYXeGpc3zMvjC07fyBkBsBBLWWaUYtZ8XOHgEBJ_n4o
                success(res) {
                    console.log('订阅消息 成功 ');
                    console.log(res)
                },
                fail(er) {
                    console.log("订阅消息 失败 ");
                    console.log(er)
                },
                       
                       

                complete: (errMsg) => {
                    console.log("数据",errMsg)
                    that.setData({
                        totalCount:that.data.totalCount - 1
                    },()=>{
                        // setTimeout(function() {
                        //     // 这里是延迟执行的代码
                        //     that.run20Func();
                        //     // that.startDraw();
                        //   }, 3000);
                       
                    })
                   
                    
                }
            })
      
      

    },
    onCloseSucess() {
        this.setData({
            shownSucess: false,
        })
    },
    fns() {
        var that = this
        var tempJson = {
            userId: that.data.userInfo.id,
            token: that.data.token,
            openid: that.data.openid,
            drawId: that.data.drawId,
            storeId: that.data.drawInfo.storeId,
            inviteUserId: that.data.inviteUserId
        };
        console.log('tempJson---',tempJson);
        // return;
        common.wxPayRequest("/wxxcxPayForStoreDraw", tempJson, function (res) {
            if (res.status == 200) {
                //微信支付
                wx.requestPayment({
                    'timeStamp': res.data.timeStamp,
                    'nonceStr': res.data.nonceStr,
                    'package': res.data.package,
                    'signType': res.data.signType,
                    'paySign': res.data.paySign,
                    'success': function (res) {
                        common.showToast('支付成功', 'success')

                        that.setData({
                            // showPop: false,
                            // backToApp: true,
                            isSelect: true,
                            shownSucess: true,
                        }, _ => {
                            that.getDrawInfo()
                        })
                    },
                    'fail': function (res) {
                        wx.hideLoading()
                        that.data.payClick = false;
                        if (res.errMsg === 'requestPayment:fail cancel') { } else {
                            common.showToast(res.errMsg)
                        }
                        console.log(res)
                        // console.log('小程序跳转到的')
                        that.setData({
                            isSelect: true
                        }, () => {
                            console.log(that.data.isSelect, "000000")
                        })
                        if (that.data.fromSmallProgramm == true) { // 从小程序支付页面跳转
                            // console.log('小程序跳转到的')
                            that.setData({
                                paySuccess: false,
                            })
                            that.popPage()
                        } else {
                            // console.log('app跳转到的')
                            that.setData({
                                payStatus: true,
                                paySuccess: false,
                            })
                        }
                    }
                })
                // setTimeout(function () {
                //     wx.hideLoading()
                //     console.log('调起');
                //     that.data.payClick = false;
                // //要延时执行的代码
                // }, 2000) //延迟时间 这里是2秒
            } else if (res.status == 400) {
                wx.hideLoading()
                that.data.payClick = false;
                common.showToast(res.msg)
                that.setData({
                    isSelect: true
                })
            } else if (res.status == 600) {
                wx.hideLoading()
                that.data.payClick = false;
                that.setData({
                    vip_list: res.data,
                    open_vip: true,
                    isSelect: true
                })
            }
        })
    },
    getRegisteryFee() { //领取报名费
        let tempJson = {
            userId: this.data.userInfo.id,
            token: this.data.token,
            orderId: this.data.drawInfo.orderId
        }
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        common.post("/storeDraw/getApplyMoney", tempJson, function (res) {
            wx.hideLoading()
            if (res.status === 200) {
                wx.showModal({
                    title: '提示',
                    content: '领取成功',
                    showCancel: false,
                    success(res) {
                        if (res.confirm) { } else if (res.cancel) { }
                    }
                })
            } else {
                wx.showModal({
                    title: '提示',
                    content: res.msg || '领取异常',
                    success(res) {
                        if (res.confirm) { } else if (res.cancel) { }
                    }
                })
            }
        }, function () {
            wx.hideLoading()
        })
        // this.setData({
        //   showDownload: true
        // })
    },
    toStore() { // 跳转店铺
        // wx.navigateTo({
        // 	url: '/packageA/pages/Goods/storePage/index?id=' + this.data.drawInfo.storeId
        // })
        common.gotoStore(this.data.drawInfo)
    },
    toDrawRank() { // 跳转抽奖排名
        wx.navigateTo({
            url: '/pages/draw/drawRank/index?drawId=' + this.data.drawInfo.id
        })
    },
    toFillAddr(e) { // 跳转 中奖后的填写收货地址
        let isSubmitAddress = e.currentTarget.dataset.issubmitaddress
        let {
            drawInfo
        } = this.data
        let parames = {
            awardName: drawInfo.awardName,
            orderId: drawInfo.orderId,
            storeAddress: drawInfo.storeAddress,
            mainImage: drawInfo.mainImage,
            storePhone: drawInfo.storePhone,
            title: drawInfo.title
        }
        if (isSubmitAddress) { // true为已经填写
            common.showToast('您已填写收货地址')
        } else {
            wx.navigateTo({
                url: '/pages/draw/fillAddr/index?parames= ' + encodeURIComponent(JSON.stringify(parames))
            })
        }
    },
    toAllApplyUser() { //跳转全部参与者页面
        // wx.navigateTo({
        //     url: '/pages/draw/allApplyUser/index?drawId=' + this.data.drawId,
        // })
        wx.navigateTo({
            url: '/packageC/pages/alllucky/alllucky?drawId=' + this.data.drawId,
        })
    },
    onShareAppMessage: function (res) { // 分享转发
        console.log('点击了---');
        // if (res.from === 'button') {
        //   // 来自页面内转发按钮
        //   console.log(res.target)
        // }
        let awardNums = this.data.drawInfo.awardNums
        let awardName = this.data.drawInfo.awardName
        return {
            title: '【免费抽奖】' + awardName  + ' '+ '数量:' + awardNums + '份',
            path: 'pages/draw/index?drawId='
                + this.data.drawInfo.id
                + '&inviteUserId=' + this.data.userInfo.id,
            imageUrl: this.data.drawInfo.mainImage,


        }

    },

    // 朋友圈
    onShareTimeline() {

        let id = this.data.drawInfo.id
        let inviteUserId = this.data.userInfo.id
        let awardNums = this.data.drawInfo.awardNums
        let awardName = this.data.drawInfo.awardName
        let data = {
            query: 'drawId=' + id
                + '&inviteUserId=' + inviteUserId,
            imageUrl: this.data.drawInfo.mainImage,
            title: this.data.title,
            title: '【免费抽奖】' + awardName + ' ' + '数量:' + awardNums + '份',
            success: function (res) {
                console.log("jdsjsdsdj", res)
            }
        }
        return data

    }
})
